#ifndef _VERTEXBUFFERMANAGER_H_
#define _VERTEXBUFFERMANAGER_H_

#pragma warning ( disable:4786 )

#include <set>

#include <d3d9.h>
#include <utillib/util/singleton.h>

struct VERTEX_PCT
{
	float x,y,z,rhw;
	DWORD color;
	float u,v;
};	

namespace interfacelib
{
	namespace DirectX
	{
		class VertexBufferManager
		{
		public:
			struct VertexBuffer
			{
				UINT length;
				DWORD usage;
				DWORD fvf;
				D3DPOOL pool;
				LPDIRECT3DVERTEXBUFFER9 vertexBuffer;
				HANDLE *handle;
			};
		private:
			typedef std::set < VertexBuffer * > vertexBufferList;
			vertexBufferList m_vertexList;
		protected:
			VertexBufferManager();	
		public:
			virtual ~VertexBufferManager();	

			SingletonInstance( VertexBufferManager );

			void initialize( LPDIRECT3DDEVICE9 device ){ m_D3DDevice = device; };
			void release();
			void releaseVertexBuffer();
			
			interfacelib::DirectX::VertexBufferManager::VertexBuffer *VertexBufferManager::createVertexBuffer( UINT length, DWORD usage, DWORD fvf, D3DPOOL pool , HANDLE *handle );

			void createVertexBuffer( interfacelib::DirectX::VertexBufferManager::VertexBuffer *vertexBuffer );
			void releaseVertexBuffer( interfacelib::DirectX::VertexBufferManager::VertexBuffer *vertexBuffer );

			void recreateVertexBuffer(){ m_recreateVertexBuffer = true ; };
			
		private:
			void insertVertexBuffer( interfacelib::DirectX::VertexBufferManager::VertexBuffer *vertexBuffer );
		private:
			bool m_recreateVertexBuffer;
			LPDIRECT3DDEVICE9 m_D3DDevice;
		};
	};
};

#endif